package com.example.administrator.fourpagelibrary.dagger;

import android.app.Activity;

import com.example.administrator.commonlibrary.bese.BaseAppliction;
import com.example.administrator.fourpagelibrary.dagger.component.ActivityComponent;
import com.example.administrator.fourpagelibrary.dagger.component.DaggerActivityComponent;
import com.example.administrator.fourpagelibrary.dagger.module.ViewModule;
import com.example.administrator.fourpagelibrary.dagger.module.ViewParameterModule;
import com.example.administrator.fourpagelibrary.fourbase.MainActivity;

/**
 * 作者：wang_hong_wei
 * 创建时间：2018/9/17
 * 描述：
 */
public class NewActivityInject implements ActivityComponent {

    private ActivityComponent build;

    public static NewActivityInject getInject() {
        return new NewActivityInject();
    }

    public <S, T> void inject(S module, T context) {
        if (module == null) module = (S) new ViewParameterModule((Activity) context);
        ViewModule mvpModule = new ViewModule((Activity) context);
        build = DaggerActivityComponent.builder().viewModule(mvpModule).viewParameterModule((ViewParameterModule) module).overallSituationComponent(BaseAppliction.getOverallSituation()).build();

        if (context instanceof MainActivity) inject((MainActivity) context);

    }

    @Override
    public void inject(MainActivity mainActivity) {
        build.inject(mainActivity);
    }
}
